<?php
include '../conn.php';
$data = json_decode($HTTP_RAW_POST_DATA);
$sql = "select * from users_info
        where id = $data->userId
        limit 1";
$isUser = $pdo->getOne($sql);
if($isUser) {
    $sql = "select count(*) as count from users_collect
            where user_id = $data->userId and notice_id = $data->noticeId
            limit 1";
    $req = $pdo->getOne($sql);
    if($req['count'] < 1) {
        $sql = "insert into users_collect
                (user_id,notice_id,status)
                values ($data->userId,$data->noticeId,$data->status)";
        $res = $pdo->query($sql);
    }else {
        $sql = "update users_collect set
                status = $data->status
                where user_id = $data->userId and notice_id = $data->noticeId";
        $res = $pdo->query($sql);
    }
}else {
    $arr = [
        "code" => 400,
        "desc" => '用户信息错误,请重试'
    ];
    echo json_encode($arr);
    exit;
}